package atm;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class MenuPanel extends JPanel  implements ActionListener {
    private ATMFrame atmFrame;
    private ImageIcon saveImg = new ImageIcon("images/buttonSave.jpg");    //存标
    private ImageIcon getImg = new ImageIcon("images/buttonGet.jpg");        //   取款
    private ImageIcon transferImg = new ImageIcon("images/buttonTransfer.jpg");   //    转账
    private ImageIcon findImg = new ImageIcon("images/buttonFind.jpg");          //     查询
    private ImageIcon changePwdPanelImg = new ImageIcon("images/buttonModify.jpg");     //    改密码
    private ImageIcon exitImg = new ImageIcon("images/buttonExit.jpg");        //      退出
   // private ImageIcon saveImg = new ImageIcon("images/buttonSave.jpg");

    private JButton saveBtn = new JButton(saveImg);
    private JButton getBtn = new JButton(getImg);
    private JButton transferBtn = new JButton(transferImg);
    private JButton findBtn = new JButton(findImg);
    private JButton changePwdPanelBtn = new JButton(changePwdPanelImg);
    private JButton exitBtn = new JButton( exitImg);

    public MenuPanel(ATMFrame atmFrame){
        this.atmFrame = atmFrame;
        this.setLayout(null);
        saveBtn.setBounds(0,150,140,50);
        getBtn.setBounds(0,210,140,50);
        transferBtn.setBounds(0,270,140,50);
        findBtn.setBounds(884,150,140,50);
        changePwdPanelBtn.setBounds(884,210,140,50);
        exitBtn.setBounds(884,270,140,50);



        saveBtn.addActionListener(this);
        getBtn.addActionListener(this);

        findBtn.addActionListener(this);
        transferBtn.addActionListener(this);
        changePwdPanelBtn.addActionListener(this);
        exitBtn.addActionListener(this);
        this.add(saveBtn);
        this.add(getBtn);
        this.add(transferBtn);
        this.add(findBtn);
        this.add(changePwdPanelBtn);
        this.add(exitBtn);

        this.setOpaque(false);
    }


    public void actionPerformed(ActionEvent e) {
        if(saveBtn == e.getSource()){
            atmFrame.switchPanel("save");
        }
        else if(getBtn == e.getSource()){
            atmFrame.switchPanel("get");
        }else if(findBtn == e.getSource()) {
            atmFrame.switchPanel("search");
            atmFrame.getSearchPanel().showBlance();
        }
        else if(transferBtn == e.getSource()){
            atmFrame.switchPanel("transfer");


        } else if(changePwdPanelBtn == e.getSource()){
            atmFrame.switchPanel("change");
        }
        else if(exitBtn == e.getSource()){
            atmFrame.switchPanel("login");
        }


    }
}